CLS
RANDOMIZE TIMER
INPUT "vvedite n"; n
INPUT "vvedite summu"; s
DIM a(n)
FOR i = 1 TO n
PRINT "vvedite a("; i; ")";
INPUT a(i)
NEXT
DO
j = j + 1: r = INT(RND * n + 1)
q = q + a(r): w$ = w$ + STR$(r) + ";"
SELECT CASE q
CASE IS > s
q = 0: w$ = ""
CASE IS = s
a$ = a$ + w$ + CHR$(179): k = k + 1: q = 0
END SELECT
LOOP UNTIL j = 10 ^ 3 OR k >= 5
PRINT a$
CLS
RANDOMIZE TIMER
INPUT "vvedite n"; n
INPUT "vvedite summu"; s
DIM a(n)
FOR i = 1 TO n
PRINT "vvedite a("; i; ")";
INPUT a(i)
NEXT
FOR i = 1 TO n ^ 2
r = INT(RND * n + 1)
q = q + a(r): w$ = w$ + STR$(r) + ";"
IF q > s THEN q = 0: w$ = ""
IF q = s THEN a$ = a$ + w$ + "|": q = 0: w$ = ""
NEXT
PRINT a$
Тестирование выполнено в программе QB64 ( Скачать )